/*
 * @Author: meifeng mei.feng@asiainfo-sec.com
 * @Date: 2022-11-17 23:37:39
 * @LastEditors: meifeng mei.feng@asiainfo-sec.com
 * @LastEditTime: 2022-11-19 20:26:46
 * @FilePath: \admin_vue\src\utils\index.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { resetRouter } from '@/router'

export function resetTokenAndClearUser() {
    // 退出登陆 清除用户资料
    localStorage.setItem('token', '')
    localStorage.setItem('userImg', '')
    localStorage.setItem('userName', '')
    // 重设路由
    resetRouter()
}

export const defaultDocumentTitle = 'vue-admin-template'
export function getDocumentTitle(pageTitle) {
    if (pageTitle) return `${defaultDocumentTitle} - ${pageTitle}`
    return `${defaultDocumentTitle}`
}
export const filterNullMiss = (en, zh) => {
    const resObj = {}
    const arr1 = Object.keys(en)
    let nullCount = 0
    arr1.filter(key => en[key] == '').forEach(item => {
        nullCount++
        resObj[item] = zh[item]
    })
    const arr2 = Object.keys(zh)
    let missCount = 0
    arr2.filter(item => !arr1.includes(item)).forEach(key => {
        missCount++
        debugger
        resObj[key] = zh[key]
    })
    console.log('空值：', nullCount, '缺失值：', missCount)
    console.log(resObj)
    return resObj
}
export const trans = (en, zh) => {
    const obj = {}
    const arr1 = Object.keys(zh)
    const arr2 = Object.keys(en)
    arr1.forEach(item => {
        if (arr2.includes(item)) {
            obj[item] = en[item]
        }
    })
    return obj
}